/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Common;

import java.io.File;
import java.util.Vector;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

/**
 *
 * @author Mario,Thomas,Max,Martin,Sergio
 */
public class XMLReader
{

    private String _fileName;

    public XMLReader(String fileName)
    {
        _fileName = fileName;
    }

    public Vector<String> ReadServerNames()
    {
        Vector<String> rval = new Vector<String>();

        try
        {
            File file = new File(_fileName);
            DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
            DocumentBuilder db = dbf.newDocumentBuilder();
            Document doc = (Document) db.parse(file);
            //doc.get.getDocumentElement().normalize();
           // System.out.println("Root element " + doc.getDocumentElement().getNodeName());
            NodeList nodeLst = doc.getElementsByTagName("server");
            //System.out.println("Information of all employees");

            for (int s = 0; s < nodeLst.getLength(); s++)
            {

                Node fstNode = nodeLst.item(s);
                
                if (fstNode.getNodeType() == Node.ELEMENT_NODE)
                {
                    rval.add(fstNode.getTextContent());
                    //rval.add(fstNode.getNodeValue());

//                    Element fstElmnt = (Element) fstNode;
//                    NodeList fstNmElmntLst = fstElmnt.getElementsByTagName("server");
//                    Element fstNmElmnt = (Element) fstNmElmntLst.item(0);
//                    NodeList fstNm = fstNmElmnt.getChildNodes();
//                    rval.add(((Node) fstNm.item(0)).getNodeValue());

                    //                    System.out.println("First Name : " + ((Node) fstNm.item(0)).getNodeValue());
//                    NodeList lstNmElmntLst = fstElmnt.getElementsByTagName("lastname");
//                    Element lstNmElmnt = (Element) lstNmElmntLst.item(0);
//                    NodeList lstNm = lstNmElmnt.getChildNodes();
//                    System.out.println("Last Name : " + ((Node) lstNm.item(0)).getNodeValue());
                }

            }
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }
        return rval;
    }
}
